package org.jeecg.modules.common.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.common.service.CommonMethodService;
import org.jeecg.modules.constant.BikeConstant;
import org.jeecg.modules.param.sysparam.entity.BikeSysParam;
import org.jeecg.modules.param.sysparam.service.IBikeSysParamService;
import org.jeecg.modules.utils.BikeResult;
import org.jeecg.modules.utils.CheckIDCardUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 公共方法
 * 月月鸟
 */
@Api(tags="公共方法")
@RestController
@RequestMapping("/common/method")
@Slf4j
public class CommonMethodController {
    @Autowired
    private CommonMethodService commonMethodService;

    @Autowired
    private IBikeSysParamService bikeSysParamService;
    /**
     * @param pickTime 借车时间
     * @param stopTime 停止计费时间
     * @return cost 费用
     * */
    @ApiOperation(value="获取费用", notes="获取费用")
    @GetMapping(value = "/getCost")
    public Result<?> getCost(@RequestParam(value = "pickTime") Date pickTime, @RequestParam("stopTime") Date stopTime) {
        String cost = commonMethodService.getCost(pickTime,stopTime);
        return Result.OK(cost);
    }

    /**
     *校验车桩编号
     * */
    @ApiOperation(value="校验车桩编号", notes="获取费用")
    @GetMapping(value = "/checkPileCode")
    public BikeResult checkPileCode(@RequestParam("pileCode")String pileCode) {
        return commonMethodService.checkPileCode(pileCode);
    }
    /**
     *
     * */
    @ApiOperation(value="校验身份证", notes="校验身份证")
    @DeleteMapping(value = "/checkIdCard")
    public Result<?> getCost(@RequestParam(value = "idCard")String idCard) {
        String replace = idCard.replace("X", "x");
        String YN = CheckIDCardUtils.IdentityCardVerification(replace);
        if (YN.equals(BikeConstant.y_n_yes)){
            return Result.OK();
        }else {
            return Result.error(YN);
        }
    }
    /**
     *
     * */
    @ApiOperation(value="身份证格式更新", notes="身份证格式更新")
    @PutMapping(value = "/checkIdCard")
    public void updateIdCard() {
        commonMethodService.updateIdCard();
    }

    @ApiOperation(value="app是否上架", notes="app是否上架")
    @GetMapping (value = "/isShelves")
    public BikeResult isShelves(){
        return BikeResult.ok("1","成功",BikeConstant.y_n_no) ;
    }

    @ApiOperation(value="app是否黑白模式", notes="app是否黑白模式")
    @GetMapping (value = "/isMonochrome")
    public BikeResult isMonochrome(){
        List<BikeSysParam> list = bikeSysParamService.list(new QueryWrapper<BikeSysParam>().eq("p_name", "param012"));
        if (!list.isEmpty()){
            BikeSysParam bikeSysParam = list.get(0);
            if (bikeSysParam.getPValue().equals(BikeConstant.y_n_no)){
                return BikeResult.ok("1","成功",BikeConstant.y_n_no) ;
            }else {
                return BikeResult.ok("1","成功",BikeConstant.y_n_yes) ;

            }
        }
        return BikeResult.ok("1","成功",BikeConstant.y_n_no) ;
    }
}
